//发货单受理详情（零担）/审核

interface IorderDetailViewModel extends ng.IScope {// extends ng.IScope
    /**
     * 订单数据
     */
    orderData: orderManagementResponse;
    /**
     * 承运商类型
     */
    carrierTypeDropDown: ValueListItemResponse[];
    /**
     * 车长枚举
     */
    carLengDropDown: ValueListItemResponse[];
    /**
     * 车型枚举
     */
    carTypeDropDown: ValueListItemResponse[];
    /**
     * 承运类别
     */
    carrierCategoryDropDown: ValueListItemResponse[];
    /**
     * 承运商级别
     */
    carrierLevel: ValueListItemResponse[];
    /**
     * 应付单价单位
     */
    receivablePriceUnitDropDown: ValueListItemResponse[];
    /**
     * 预付款方式下拉
     */
    advancePriceTypeDropDown: ValueListItemResponse[];

    /**
     * 附件上传组件
     */
    attachmentUploader: any;

    /**
     * 新增承运商数据视图
     */
    carrierAddData: carrierData;
    /**
     * 新增承运商
     */
    openCarrier: () => void;
    /**
     * 新增车辆
     */
    openCar: () => void;
    /**
     * 添加车辆数据视图
     */
    carAddData: carAddData;
    /**
     * 承运商数据
     */
    carrierDetailData: carryOrderResponse;
    /**
     * 订单列表
     */
    orderList: Array<orderList>,
    /**
     * 承运商编号
     */
    carrierId: string,
    /**
     * 承运商名称
     */
    carrierName: string;
    /**
     * 承运商号码
     */
    carrierPhone: string;
    /**
    *承运商类型
    */
    carrierType: string;
    /**
    *车辆id
    */
    carId_: string;
    /**
     * 查看详情的车辆ID
     */
    checkDetailCarid:string;
    
    /**
    *车牌号
    */
    carCode_: string;
    /**
    *驾驶员号码
    */
    driverPhone: string;
    /**
    *驾驶员名称
    */
    driverName: string;
    /**
    *承运车辆车长
    */
    carLength: string;
    /**
    *承运车辆车型
    */
    carType: string;
    /**
    *承运单应付单价
    */
    carrierReceivablePirce: string;
    /**
    *承运单应付单价单位
    */
    carrierReceivablePirceUnit: string;
    /**
    *承运单应付说明
    */
    carrierReceivableRemarks: string;
    /**
     * 预付款1
     */
    advancePrice: string;
    /**
    *预付款1单位
    */
    advancePriceType: string;
    /**
     * 预付款2
     */
    advancePriceTwo: string;
    /**
     * 预付款2单位
     */
    advancePriceTypeTwo: string;
    /**
    *回单款
    */
    receiptPrice: number;
    /**
    *回单款付款方式
    */
    receiptPriceType: string;
    /**
    *银行卡号
    */
    bankCode: string;
    /**
    *账户编号
    */
    bankId: string;
    /**
    *开户银行
    */
    openBank: string;
    /**
    *持卡人
    */
    holder: string;
    /**
     * 承运单备注
     */
    carryOrderRemarks: string,
    /**
     * 保存承运单
     */
    confirmC: () => void;

    /**
     * 删除承运单
     */
    deleteCarrier: () => void;
    /**
     * 删除订单列表
     */
    deleteOrderList: (row: orderList) => void;
    /**
     * 获取订单详情
     */
    clickGetOrderDetail: (id: string) => void;
    /**
     * 获取总单数据
     */
    getOrderDetial: (data: orderManagementResponse) => void;
    /**
     * 获取子单数据
     */
    EditChildren: (data: invoiceManagementOrderChild) => void;
    /**
     * 总订单列表
     */
    orderTotalList: Array<orderManagementResponse>;
    /**
     * 子单列表
     */
    orderChildList: Array<invoiceManagementOrderChild>;
    /**
     * 总单数据
     */
    orderDetail: orderManagementResponse;
    /**
     * 子单数据
     */
    orderChildData: invoiceManagementOrderChild;
    /**
     * 变换调度
     */
    changeDispatch: (id: string) => void;
    /**
     * 调度专员编号
     */
    dispatcherId: string;
    /**
     *调度专员下拉列表
     */
    dispatchOfficerDropDown: EmployeeListItemResponse[];
    /**
      * app竞价
      */
    orderAppBiddingList: Array<quotationResponse>;
    /**
     * 定位
     */
    location: () => void;
    /**
     * 定位车辆id
     */
    carId: string;
    /**
     * 是否为车辆定位
     */
    isVehicle: boolean;
    /**
    *车牌号
    */
    carCode: string;
    /**
    *手机号
    */
    phoneNumber: string;
    /**
    *历史定位地点
    */
    areaS: string;
    /**
    *历史定位时间
    */
    creationTimeS: string;
    /**
    *定位注册按钮启用禁用
    */
    isdisabled1: boolean;
    /**
    *定位按钮启用禁用
    */
    isdisabled2: boolean;

    /**
     * 承运商自动补全
     */
    searchCarrier: (value: string) => void;
    /**
     * 选择承运商
     */
    carrierSelect: (data: angucomplete<CarrierListItemResponse>) => void;
    /**
    * 车牌号自动补全
    */
    searchCar: (value: string) => any
    /**
     * 选择车牌号事件
     */
    carCodeSelect: (selected: angucomplete<CarListItemResponse>) => void;
    /**
     * 银行卡自动补全
     */
    searchBank: (value: string) => void;
    /**
     * 选择银行卡号事件
     */
    bankCodeSelect: (data: angucomplete<BankListItemResponse>) => void;
    /**
     * 银行卡change事件
     */
    getBankName: () => void;
    /**
     * 开户银行按钮显示隐藏
     */
    openBankDis: boolean;
    /**
     * 删除承运单按钮显示隐藏
     */
    delShow: boolean;
    /**
     * 确定按钮显示隐藏
     */
    saveBtn: boolean;
    saveDis: boolean;
    /**
     * 取消
     */
    cancelC: () => void;

    /////////////////////////

    /**
    *送货地址
    */
    deliverAddress: string;
    deliverAddress_?: string

    /**
    *发货时间
    */
    shipAddress: string;
    shipAddress_: string;
    /**
     * 道路运输许可证号
     */
    permitNumber: string;
    /**
     * 所属辖区省
     */
    countrySubdivisionProvinceCode: string;
    /**
   * 所属辖区市
   */
    countrySubdivisionCityCode: string;
    /**
   * 所属辖区区
   */
    countrySubdivisionCountryCode: string;
    /**
    * 道路运输证字号
    */
    roadTransportCertificateNumber: string;
    /**
     * 所属辖区code
     */
    countrySubdivisionCode: string;
    /**
     * 所属辖区省--新增车辆
     */
   provinceCode: string;
    /**
   * 所属辖区市
   */
    cityCode: string;
    /**
   * 所属辖区区
   */
   areaCode: string;
    /**
     * 所属辖区市列表
     */
    deliverCityList: any;
    /**
     * 所属辖区区列表
     */
    deliverAreaList: any;





    //11.1新增
    /**
     * App竞价查看车辆信息
     */
    carDetailApp: (item: quotationResponse) => void;
  
    //app竞价中北斗定位
    carDBLocationApp:(item:quotationResponse) => void;
     /**
     * 北斗定位，模态框中的返回事件
     */
    bd_back:()=>void;
    
    /**
     * 北斗定位 司机姓名
     */
    bd_driverName:string;
    
    /**
     * 北斗定位 司机电话
     */
    bd_phoneNumber:string;
    // 北斗定位 车牌号
    bd_carCode:string;

    bd_creationTime:string;
    bd_statusCode:string;
    bd_areaInfo:string

     // 车辆信息详情弹窗 附件信息 图片点击事件
     handleImgClick:(item)=>void;
     // 车辆信息详情弹窗 附件信息 图片点击 被点击的图片的路径
     selectedImgSrc:string;

    /**
     * 12.14新增：身份证号
     */
    carID:string;

}


// App车辆详情中的查询条件
interface IOrderAcceptBankCardBulkQueryTerms{
    //交易记录的查询条件
    /**
     * 货物名称
     */
    goodsNameAppCarBulk: string;
    /**
     * 货物数量
     */
    goodsNumAppCarBulk: string;
    /**
     * 线路地址
     */
    routeAppCarBulk: string;
    /**
     * 发货地址
     */
    shipAddressAppCarBulk: string;
    /**
     * 送货地址
     */
    deliverAddressAppCarBulk: string;
}

//App竞价的北斗定位
interface BDParamsBulk extends angular.ui.IStateParamsService{
    idBD;
    carcodeBD;
    phoneBD;
    shipAddressBD;
    deliverAddressBD;
}







/**
 * 添加承运商数据视图
 */
interface carrierData {
    /**
     * 承运商类型
     */
    type: string;
    /**
     * 承运商名称
     */
    name: string;
    /**
     * 承运商号码
     */
    phone: string;
    /**
     * 承运商地址
     */
    address: string;
    /**
     * 承运商等级
     */
    level: string;
    /**
     * 保存
     */
    addCarrier: () => void;
}

/**
 * 添加车辆数据视图
 */
interface carAddData {
    /**
     * 车牌号
     */
    carCode: string;
    /**
     * 车型
     */
    carType: string;
    /**
     * 车长
     */
    carLength: string;
    /**
     * 核定载量
     */
    bearing: string;
    /**
     * 驾驶员姓名
     */
    driver: string;
    /**
     * 驾驶员号码
     */
    driverPhone: string;
    /**
     * 承运商类别
     */
    carrierCategory: string;
    /**
     * 车辆来源
     */
    carSource: string;
    /**
    * 道路运输许可证号
    */
    permitNumber: string;
    /**
    * 所属辖区
    */
    countrySubdivisionCode: string;
    /**
    * 道路运输证字号
    */
    roadTransportCertificateNumber: string;
    /**
     * 地址
     */
    address: string;
    /**
     * 身份证号码
     */
    identity:string;
    /**
     * 保存
     */
    addCar: () => void;

}



class OrderAcceptBreakController  {
    /**
     * 承运商是否存在银行卡
     */
    isCarrBank: boolean;
    /**
     * 是否填写车辆银行卡
     */
    isCarBank: boolean;
    /**
     * 订单可识别编号
     */
    orderCode: string;
    /**
     * 订单id列表
     */
    orderIdList: Array<string>;
    /**
     * 订单状态
     */
    type: string;

    /**
     * 承运单id
     */
    order_carrierId: string;
    /**
     * 预付款列表
     */
    advancePaymentList: Array<advancePaymentList>;
    /**
     * 附件地址
     */
    baseImageUrl: string;
    /**
     * 附件数据
     */
    uploaderList: Array<AddCarAttachmentDetail>;
    /**
     * 车辆定位状态
     */
    locationStatus: boolean;




   

  


    constructor(private $scope: IorderDetailViewModel, private $timeout: ng.ITimeoutService, private locationService: ILocationService,  private $state: angular.ui.IStateService, private $location: ng.ILocationService,
        private $http: ng.IHttpService, private orderService: IorderService, private carrierService: ICarrierService, private carService: ICarService, private employeeService: IEmployeeService,
        private bankService: IBankService, private valueService: IValueService, private routeService: routeService, private $stateParams: BDParamsBulk, private $ngBootbox: BootboxService, private commonService: ICommonService, 
        private areaService: IAreaService,private $rootScope:ImainRootScope,private ossUploaderService:ossUploaderService) {
        

        
        this.uploaderList = [];
        this.baseImageUrl = this.routeService.getBaseUrl() + "attachment/";

       
        // this.uploaderListApp = [];

        this.init();
    }

    /*初始化*/
    init(): void {
        

        this.isCarrBank = false;
        this.isCarBank = false;
        this.orderCode = this.$location.search().id;
        this.order_carrierId = this.$location.search().carrierId;
        this.type = this.$location.search().type;
        this.orderIdList = [];
        this.advancePaymentList = [];
        this.$scope.advancePrice = "";
        this.$scope.advancePriceType = "";
        this.$scope.advancePriceTwo = "";
        this.$scope.advancePriceTypeTwo = "";
        this.$scope.receiptPrice = null;
        this.$scope.receiptPriceType = "";
        this.$scope.openCarrier = this.showDialogOpenCarrier;
        this.$scope.openCar = this.showDialogOpenCar;
        /**
         * 自动补全
         */
        this.$scope.searchCarrier = this.searchCarrier;
        this.$scope.searchCar = this.searchCar;
        this.$scope.searchBank = this.searchBank;
        /**
         * 选择事件
         */
        this.$scope.carrierSelect = this.carrierSelect;
        this.$scope.carCodeSelect = this.carCodeSelect;
        this.$scope.bankCodeSelect = this.bankCodeSelect;

        /**
         * change事件
         */
        this.$scope.getBankName = this.commonService.debounce(this.getBankName, 500);

        this.$scope.openBankDis = true;
        this.$scope.delShow = false;
        this.$scope.saveBtn = true;
        this.$scope.saveDis = false;
        this.$scope.cancelC = this.cancelC;
        //枚举下拉
        this.loadValueDropDown();

        const OssFile = this.ossUploaderService.getOssFile();
        this.$scope.attachmentUploader= new OssFile(this.$scope,this.$scope.attachmentUploader,{uploaderList:this.uploaderList,tag:1,multiple:true});

        if (this.type == "退回派车") {
            this.$scope.delShow = true;
            this.orderService.carryOrder(this.order_carrierId).then(result => {
                this.$scope.carrierDetailData = result.data;
                this.$scope.carrierId = result.data.carrierId;
                this.$scope.carrierName = result.data.carrierName;
                this.$scope.carrierPhone = result.data.carrierPhone;
                this.$scope.carrierType = result.data.carrierType;

                this.$scope.carId_ = result.data.carId;
                this.$scope.carCode_ = result.data.carCode;
                this.$scope.driverPhone = result.data.driverPhone;
                this.$scope.driverName = result.data.driverName;
                this.$scope.carLength = result.data.carLength;
                this.$scope.carType = result.data.carType;

                //12.14新增：身份证号
                this.$scope.carID = result.data.identity;


                //获取订单列表
                this.orderService.list("", true, result.data.orderCodeList.join(), "", "", "", "", "", "", "", "", "", "", "", 0, -1).then(res => {
                    this.$scope.orderList = res.data.data;
                    //获取订单编号
                    this.$scope.orderList.forEach((item) => {
                        this.orderIdList.push(item.id);
                    });
                });

                /*无车承运 */
                this.$scope.permitNumber = result.data.permitNumber;
                this.$scope.countrySubdivisionProvinceCode = result.data.countrySubdivisionProvinceCode;
                this.$scope.countrySubdivisionCityCode = result.data.countrySubdivisionCityCode;
                this.$scope.countrySubdivisionCountryCode = result.data.countrySubdivisionCountryCode;
                this.$scope.roadTransportCertificateNumber = result.data.roadTransportCertificateNumber;
                this.getProvinceList();
                /*无车承运end */


                this.carService.getDetail(this.$scope.carId_).then((res) => {
                    this.locationStatus = res.data.locationStatus;
                    let car = res.data.carCode + " " + res.data.driver + " " + res.data.driverPhone;
                    $("#car_value").val(car);
                });
                this.$scope.carrierReceivablePirce = String(result.data.carrierReceivablePirce);
                this.$scope.carrierReceivablePirceUnit = result.data.carrierReceivablePirceUnit;
                this.$scope.carrierReceivableRemarks = result.data.carrierReceivableRemarks;
                result.data.advancePaymentList.forEach((item, index) => {
                    switch (index) {
                        case 0:
                            this.$scope.advancePrice = String(item.advancePrice);
                            this.$scope.advancePriceType = item.advancePriceType;
                            break;
                        case 1:
                            this.$scope.advancePriceTwo = String(item.advancePrice);
                            this.$scope.advancePriceTypeTwo = item.advancePriceType;
                            break;
                    }
                });
                this.$scope.receiptPrice = result.data.receiptPrice;
                this.$scope.receiptPriceType = result.data.receiptPriceType;
                this.$scope.bankCode = result.data.bankCode;
                this.$scope.bankId = result.data.bankId;
                this.$scope.openBank = result.data.openBank;
                this.$scope.holder = result.data.holder;
                this.isCarrBank = true;
                this.$scope.carryOrderRemarks = result.data.carryOrderRemarks;
            });
            this.$scope.deleteCarrier = this.deleteCarrier;
        } else if (this.type == "派车中") {
            this.$scope.deleteOrderList = this.deleteOrderList;
            //获取订单列表
            this.orderService.list("", true, this.orderCode, "", "", "", "", "", "", "", "", "", "", "", 0, -1).then(res => {
                this.$scope.orderList = res.data.data;
                //获取订单编号
                this.$scope.orderList.forEach((item) => {
                    this.orderIdList.push(item.id);
                });
            });
        }
        this.$scope.clickGetOrderDetail = this.clickGetOrderDetail;
        this.$scope.location = this.location;
        this.$scope.confirmC = this.confirmC;

        //11.1新增
        //App竞价列表中查看车辆信息
        this.$scope.carDetailApp =this.carDetailApp;
        //App竞价列表中北斗定位
        this.$scope.carDBLocationApp = this.carDBLocationApp;
        //北斗定位的地图初始化
        this.$scope.bd_back = ()=>{
            $('#carOrderBDNPLocationBulk').modal('hide');
        }

        $('#orderAcceptBulkDetail').on('hidden.bs.modal',  (e)=> {
            this.$rootScope.tcr_startAddress=null;
            if (!this.$scope.$$phase) {
                this.$scope.$apply(() => { this.$rootScope.tcr_startAddress });
            }
        })

        this.$scope.handleImgClick=(item)=>{
            
            $('#imgRotate').modal('show');
            this.$scope.selectedImgSrc=item.imgSrc;
        }

    }


    /**
     * 获取市区下拉
     */
    getProvinceList = () => {
        if(this.$scope.countrySubdivisionProvinceCode === "" || !this.$scope.countrySubdivisionProvinceCode){return;};
        this.areaService.getCity(this.$scope.countrySubdivisionProvinceCode).then(res => {
            this.$scope.deliverCityList = res.data.data;
        });

        if(this.$scope.countrySubdivisionCityCode === "" || !this.$scope.countrySubdivisionCityCode){return;};
        this.areaService.getCounty(this.$scope.countrySubdivisionCityCode).then(res => {
            this.$scope.deliverAreaList = res.data.data;
        });
    }

    /**
     * 枚举下拉
     */
    loadValueDropDown(): void {
        let valueData = this.valueService;
        this.$scope.carrierTypeDropDown = valueData.getCarrierTypeList().data;
        this.$scope.carLengDropDown = valueData.getCarLengthList().data;
        this.$scope.carTypeDropDown = valueData.getCarTypeList().data;
        this.$scope.carrierCategoryDropDown = valueData.getCarriageTypeList().data;
        this.$scope.carrierLevel = valueData.getCarrierLevelList().data;
        let getPriceUnitList = valueData.getPriceUnitList().data;
        getPriceUnitList.splice(valueData.getPriceUnitList().data.length - 2, 1);
        this.$scope.receivablePriceUnitDropDown = getPriceUnitList;
        this.$scope.advancePriceTypeDropDown = valueData.getPaymentMethodList().data;
    }

    /**
     * 显示新增承运商弹窗
     */
    showDialogOpenCarrier = () => {
        this.$scope.carrierAddData = {
            type: "",
            name: "",
            phone: "",
            address: "",
            level: "",
            addCarrier: this.addCarrierData
        }
    }

    /**
     * 新增承运商
     */
    addCarrierData = () => {
        this.carrierService.add(
            this.$scope.carrierAddData.name,
            this.$scope.carrierAddData.type,
            this.$scope.carrierAddData.phone,
            this.$scope.carrierAddData.level,
            this.$scope.carrierAddData.address
        ).then(res => {
            this.$ngBootbox.alert("添加承运商成功");
            $('#CarrierAdd').modal('hide');
        })
    }

    /**
     * 显示新增车辆弹窗
     */
    showDialogOpenCar = () => {
        this.$scope.carAddData = {
            carCode: "",
            carType: "",
            carLength: "",
            bearing: "",
            driver: "",
            driverPhone: "",
            carrierCategory: "",
            carSource: "",
            permitNumber: "",
            countrySubdivisionCode: "",
            roadTransportCertificateNumber: "",
            address: "",
            identity:"",
            addCar: this.addCarData
        }
    }

    /**
     * 新增车辆
     */
    addCarData = () => {
         if (this.$scope.areaCode != "-1") {
            this.$scope.carAddData.countrySubdivisionCode = this.$scope.areaCode;
        } else if (this.$scope.areaCode == "-1" && this.$scope.cityCode != "-1") {
            this.$scope.carAddData.countrySubdivisionCode = this.$scope.cityCode;
        } else if (this.$scope.cityCode == "-1" && this.$scope.provinceCode != "-1") {
            this.$scope.carAddData.countrySubdivisionCode = this.$scope.provinceCode;
        }
        this.carService.add(
            this.$scope.carAddData.carCode.toUpperCase(),
            this.$scope.carAddData.carType,
            this.$scope.carAddData.carLength,
            this.$scope.carAddData.driver,
            this.$scope.carAddData.driverPhone,
            this.$scope.carAddData.carrierCategory,
            Number(this.$scope.carAddData.bearing),
            this.$scope.carAddData.carSource,
            this.$scope.carAddData.permitNumber,
            this.$scope.carAddData.countrySubdivisionCode,
            this.$scope.carAddData.roadTransportCertificateNumber,
            this.$scope.carAddData.address,
            this.$scope.carAddData.identity.toUpperCase()
        ).then(res => {
            this.$ngBootbox.alert("添加车辆成功");
            $('#CarsAdd').modal('hide');
        })
    }
    /**
     * 预付款
     */
    advanceListPush = () => {
        this.advancePaymentList.push({ advancePrice: parseFloat(this.$scope.advancePrice), advancePriceType: this.$scope.advancePriceType });
        this.advancePaymentList.push({ advancePrice: parseFloat(this.$scope.advancePriceTwo), advancePriceType: this.$scope.advancePriceTypeTwo });
    }

    /**
     * 保存承运单
     */
    confirmC = () => {
        if (!$("#AcceptForm").valid()) { return; };
        if( !this.$scope.carID || this.$scope.carID && !this.$scope.carID.match(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|x|X)$/)){
            this.$ngBootbox.alert("请填写正确的身份账号");
            return;
        }
        if(!this.$scope.carrierPhone || this.$scope.carrierPhone && !this.$scope.carrierPhone.match(/^1\d{10}$/)){
            this.$ngBootbox.alert("请填写正确的承运商号码");
            return;
        }
        if(!this.$scope.carCode_ || this.$scope.carCode_ && !this.$scope.carCode_.match(/^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{5}$/)){
            this.$ngBootbox.alert("请填写正确的车牌号");
            return;
        }
        if(!this.$scope.driverPhone || this.$scope.driverPhone && !this.$scope.driverPhone.match(/^1\d{10}$/)){
            this.$ngBootbox.alert('请输入正确的驾驶员号码');
            return;
        }
        if(!this.$scope.carrierReceivablePirce || this.$scope.carrierReceivablePirce && !this.$scope.carrierReceivablePirce.match(/^[0-9]+(\.[0-9]{1,2})?$/)){
            this.$ngBootbox.alert('请输入正确的应付单价');
            return;
        }
        // console.log('d',this.$scope.advancePrice)
        if(this.$scope.advancePrice===undefined || this.$scope.advancePrice && !this.$scope.advancePrice.match(/^[0-9]+(\.[0-9]{1,2})?$/) || this.$scope.advancePriceTwo===undefined ||this.$scope.advancePriceTwo && !this.$scope.advancePriceTwo.match(/^[0-9]+(\.[0-9]{1,2})?$/) ){
            this.$ngBootbox.alert('请输入正确的预付款');
            return;
        }

        if (this.type == "退回派车") {
            // if (!$("#AcceptForm").valid()) { return; };
            this.$scope.saveBtn = true;
            this.$ngBootbox.confirm("是否确认派车?").then(() => {
                this.advanceListPush();
                this.orderService.editCarrierOrder(
                    this.order_carrierId,
                    this.orderIdList,
                    this.$scope.carrierId,
                    this.$scope.carrierName,
                    this.$scope.carrierPhone,
                    this.$scope.carrierType,
                    this.$scope.carId_,
                    this.$scope.carCode_,
                    this.$scope.driverPhone,
                    this.$scope.driverName,
                    this.$scope.carLength,
                    this.$scope.carType,
                    Number(this.$scope.carrierReceivablePirce),
                    this.$scope.carrierReceivablePirceUnit,
                    this.$scope.carrierReceivableRemarks,
                    this.advancePaymentList,
                    this.$scope.receiptPrice,
                    this.$scope.receiptPriceType,
                    this.$scope.holder,
                    this.$scope.bankId,
                    $("#bankCode_value").val(),
                    this.$scope.openBank,
                    this.$scope.carryOrderRemarks,
                    [],
                    "",
                    this.locationStatus,
                    this.$scope.permitNumber,
                    this.$scope.countrySubdivisionProvinceCode,
                    this.$scope.countrySubdivisionCityCode,
                    this.$scope.countrySubdivisionCountryCode,
                    this.$scope.roadTransportCertificateNumber,
                    this.$scope.carID   //12.14新增：身份证号
                ).then(res => {
                    this.$state.go("app.order.orderAcceptList", { name: 'accept' });
                    this.$scope.saveDis = true;
                    this.$scope.saveBtn = false;
                }, ref => {
                    this.$scope.saveDis = false;
                    this.$scope.saveBtn = true;
                });
            });
        }
        else if (this.type == "派车中") {
            // if (!$("#AcceptForm").valid()) { return; };
            this.$scope.saveBtn = true;
            this.$ngBootbox.confirm("是否确认派车?").then(() => {
                this.advanceListPush();
                this.orderService.addCarryOrder(
                    this.orderIdList,
                    this.$scope.carrierId,
                    this.$scope.carrierName,
                    this.$scope.carrierPhone,
                    this.$scope.carrierType,
                    this.$scope.carId_,
                    this.$scope.carCode_,
                    this.$scope.driverPhone,
                    this.$scope.driverName,
                    this.$scope.carLength,
                    this.$scope.carType,
                    Number(this.$scope.carrierReceivablePirce),
                    this.$scope.carrierReceivablePirceUnit,
                    this.$scope.carrierReceivableRemarks,
                    this.advancePaymentList,
                    this.$scope.receiptPrice,
                    this.$scope.receiptPriceType,
                    this.$scope.holder,
                    this.$scope.bankId,
                    $("#bankCode_value").val(),
                    this.$scope.openBank,
                    this.$scope.carryOrderRemarks,
                    [],
                    "",
                    this.locationStatus,
                    this.$scope.permitNumber,
                    this.$scope.countrySubdivisionProvinceCode,
                    this.$scope.countrySubdivisionCityCode,
                    this.$scope.countrySubdivisionCountryCode,
                    this.$scope.roadTransportCertificateNumber,
                    this.$scope.carID   //12.14新增：身份证号
                ).then(res => {
                    this.$state.go("app.order.orderAcceptList", { name: 'accept' });
                    this.$scope.saveDis = true;
                    this.$scope.saveBtn = false;
                });
            });
        }
        else {
            this.$scope.saveBtn = false;
            return;
        }
    }

    /**
     * 删除承运单
     */
    deleteCarrier = () => {
        this.$ngBootbox.confirm("确定删除承运单吗？").then(() => {
            this.orderService.deleteCarrierOrder(this.order_carrierId).then(res => {
                this.$state.go("app.order.orderAcceptList", { name: 'accept' });
            });
        }, () => { return; });
    }

    /**
     * 删除订单列表
     */
    deleteOrderList = (row: orderList) => {
        if (this.$scope.orderList.length > 0) {
            //删除订单id(数据)
            this.orderIdList.forEach((item, index) => {
                if (row.id == item) {
                    this.orderIdList.splice(index, 1);
                }
            });
            //删除视图
            this.$scope.orderList.forEach((item, index) => {
                if (row.id == item.id) {
                    this.$scope.orderList.splice(index, 1);
                }
            })
        } else { this.$ngBootbox.alert("无法删除"); return };
    }

    /**
     * 获取订单详情
     */
    clickGetOrderDetail = (id: string) => {
        this.orderService.orderManagentDetail(id).then(res => {
            this.$scope.orderData = res.data;
            this.$scope.orderTotalList = [res.data];
            this.$scope.orderChildList = res.data.childList;
            //调度专员下拉
            this.employeeService.getbytype(CommissionerType.Dispatch.toString(), 0, -1).then(result => {
                this.$scope.dispatchOfficerDropDown = result.data.data;
                this.$scope.dispatcherId = String(res.data.dispatcherId);
            });
            this.$scope.getOrderDetial = this.getOrderDetial;
            this.$scope.EditChildren = this.EditChildren;
            this.getQuotationList(res.data.id);
            //附件
         

            
            this.$scope.attachmentUploader.clearQueue()


            res.data.orderAttachments.forEach((item, index) => {
                this.uploaderList.push(item);
                
                this.$scope.attachmentUploader.addByAttach(item)
            });
            this.$scope.changeDispatch = this.changeDispatch;


            this.$rootScope.tcr_startAddress=res.data.originProvinceStr+res.data.originCityStr+res.data.originCountyStr+res.data.originDetails;
            this.$rootScope.tcr_endAddress=res.data.destinationProvinceStr+res.data.destinationCityStr+res.data.destinationCountyStr+res.data.destinationDetails;
           
            this.$rootScope.tcr_startCityCode=res.data.originCity;
            this.$rootScope.tcr_endCityCode=res.data.destinationCity;

            
        });
    }

    /**
     * 获取总单数据
     */
    getOrderDetial = (data: orderManagementResponse) => {
        this.$scope.orderDetail = data;
    }
    /**
     * 获取子单数据
     */
    EditChildren = (data: invoiceManagementOrderChild) => {
        this.$scope.orderChildData = data;
    }

    /**
     * 获取App竞价列表
     */
    getQuotationList = (id: string) => {
        this.orderService.quotation(id).then(res => {
            this.$scope.orderAppBiddingList = res.data.data;
        });
    }

    /**
     * 变换调度
     */
    changeDispatch = () => {
        let phone;
        this.$scope.dispatchOfficerDropDown.forEach((item, index) => {
            if (item.id == this.$scope.dispatcherId) {
                phone = item.phoneNumber;
            }
        });
        this.orderService.editOfficer(this.$scope.orderData.id, this.$scope.dispatcherId, $("#orderAccept_breakBulk_dispatchOfficerId option:selected").text(), phone, "", "").then(res => {
            $("#orderTotal").modal("hide");
            this.$timeout(() => {
                this.$state.go("app.order.orderAcceptList", { name: "accept" });
            });
        }, (rej) => { });
    }

    /**
     * 定位事件
     */
    location = () => {
        if (!this.$scope.carId_) {
            this.$ngBootbox.alert("请填写车辆信息");
            return;
        }
        $("#location").modal("show");

        let carId = this.$scope.carId_;
        this.$scope.carId = this.$scope.carId_;
        this.$scope.isVehicle = true;

        this.$scope.carCode = this.$scope.carCode_;
        let driverPhone = this.$scope.driverPhone;
        this.$scope.phoneNumber = this.$scope.driverPhone;

        this.locationService.getHistoryLocation(carId, true).then((resq) => {
            this.$scope.areaS = resq.data.area;
            this.$scope.creationTimeS = resq.data.creationTime;
        }, (rel) => { console.log(rel); }
        );


        this.locationService.getLocationState(carId, true).then((res) => {
            if (res.data.isRegister == true) {
                this.$scope.isdisabled1 = true;
                this.$scope.isdisabled2 = false;
            } else {
                this.$scope.isdisabled1 = false;
                this.$scope.isdisabled2 = true;
            }
        }, (rej) => {
            this.$scope.isdisabled1 = true;
            this.$scope.isdisabled2 = true;
        }
        )
    }
    /**
     * 承运商自动补全事件
     */
    searchCarrier = (value: string) => {
        return this.carrierService.getList(null, null, value, "", "", "", "", "", true, 0, 5).then((res) => {
            return res.data.data;
        });
    }

    /**
     * 选择承运商
     */
    carrierSelect = (data: angucomplete<CarrierListItemResponse>) => {
        if (data) {
            this.$scope.carrierId = data.originalObject.id;
            this.$scope.carrierName = data.originalObject.name;
            this.$scope.carrierPhone = data.originalObject.phone;
            this.carrierService.getDetail(data.originalObject.id).then((res) => {
                this.$scope.carrierType = res.data.type;
            });
            this.searchCarrierBank(this.$scope.carrierId);
        }
    }

    /**
     * 获取承运商银行卡信息
     */
    searchCarrierBank = (carrierId: string) => {
        this.bankService.getList("", carrierId, "", false, 0, 5).then(res => {
            if (this.type == "退回派车") {
                if (this.isCarrBank) {
                    return;
                } else {
                    if (res.data.data.length > 0) {
                        let bankData = res.data.data[0]
                        this.$scope.holder = bankData.holder;
                        this.$scope.openBank = bankData.bank;
                        $("#bankCode_value").val(bankData.cardNumber);
                        this.$scope.bankId = bankData.id;
                        this.isCarrBank = true;
                    } else {
                        this.isCarrBank = false;
                    }
                }
            } else {
                if (res.data.data.length > 0) {
                    let bankData = res.data.data[0]
                    this.$scope.holder = bankData.holder;
                    this.$scope.openBank = bankData.bank;
                    $("#bankCode_value").val(bankData.cardNumber);
                    this.$scope.bankId = bankData.id;
                    this.isCarrBank = true;
                } else if (this.isCarBank && !this.isCarrBank) {
                    return;
                } else {
                    this.$scope.holder = "";
                    this.$scope.openBank = "";
                    $("#bankCode_value").val("");
                    this.$scope.bankId = "";
                    this.isCarrBank = false;
                }
            }
        });
    }

    /**
     * 车牌号自动补全
     */
    searchCar = (value: string) => {
        return this.carService.keywordlist(value, 0, 5).then((res) => {
            return res.data.data;
        });
    }

    /**
     * 选择车牌号事件
     */
    carCodeSelect = (selected: angucomplete<CarListItemResponse>) => {
        if (selected) {
            this.$scope.carId_ = selected.description.id;
            this.$scope.carCode_ = selected.description.carCode;
            this.$scope.driverPhone = selected.description.driverPhone;
            this.$scope.driverName = selected.description.driver;

            this.carService.getDetail(this.$scope.carId_).then((res) => {
                //12.14新增：身份证号
                this.$scope.carID = res.data.identity;
                
                this.$scope.carLength = String(res.data.carLengthInt);
                this.$scope.carType = String(res.data.carTypeInt);
                this.locationStatus = res.data.locationStatus;
                this.$scope.countrySubdivisionCode = res.data.countrySubdivisionCode;
                this.$scope.permitNumber = res.data.permitNumber;
                this.$scope.roadTransportCertificateNumber = res.data.roadTransportCertificateNumber;
                let countrySubdinvisionCode = this.$scope.countrySubdivisionCode;
                if (this.$scope.countrySubdivisionCode != undefined || this.$scope.countrySubdivisionCode != null) {
                    this.$scope.countrySubdivisionProvinceCode = countrySubdinvisionCode.substring(0, 2);
                    this.$scope.countrySubdivisionCityCode = countrySubdinvisionCode.substring(0, 4);
                    this.$scope.countrySubdivisionCountryCode = countrySubdinvisionCode.substring(0, 6);
                    this.getProvinceList();
                }else{
                     this.$scope.countrySubdivisionProvinceCode = "-1";
                    this.$scope.countrySubdivisionCityCode = "-1";
                    this.$scope.countrySubdivisionCountryCode = "-1";
                }
            });
            this.searchCarBank(this.$scope.carId_);
        } else { return };
    }

    /**
     * 获取车辆银行卡信息
     */
    searchCarBank = (carId: string) => {
        if (!this.isCarrBank) {
            this.carService.getDetail(carId).then((res) => {
                if (res.data.bankList.length < 1) {
                    $("#bankCode_value").val("");
                    this.$scope.bankCode = "";
                    this.$scope.openBank = "";
                    this.$scope.holder = "";
                    return;
                }
                $("#bankCode_value").val(res.data.bankList[0].cardNumber);
                this.$scope.bankId = res.data.bankList[0].id;
                this.$scope.bankCode = res.data.bankList[0].cardNumber;
                this.$scope.openBank = res.data.bankList[0].bank;
                this.$scope.holder = res.data.bankList[0].holder;
                this.isCarBank = true;
            });
        }
    }

    /**
     * 银行卡自动补全
     */
    searchBank = (value: string) => {
        return this.bankService.getList(this.$scope.carId_, this.$scope.carrierId, value, false, 0, 5).then((res) => {
            return res.data.data;
        });
    };

    /**
     * 选择银行卡号
     */
    bankCodeSelect = (data: angucomplete<BankListItemResponse>) => {
        if (data) {
            this.$scope.holder = data.description.holder;
            this.$scope.openBank = data.description.bank;
            this.$scope.bankId = data.description.id;
        }
    }

    /**
     * 获取银行名称
     */
    getBankName = () => {
        let bankL = $("#bankCode_value").val().length;
        if (bankL > 15) {
            this.bankService.getBankName($("#bankCode_value").val()).then(res => {
                if (!res) {
                    this.$scope.openBank = "";
                    this.$scope.openBankDis = false;
                } else {
                    this.$scope.openBank = res.data;
                    this.$scope.openBankDis = true;
                }
            }, (ref) => {
                this.$scope.openBankDis = false;
                return;
            })
        }
    }

    /**
     * 取消
     */
    cancelC(): void {
        this.$state.go("app.order.orderAcceptList", { name: 'accept' });
    }

    //11.1新增

    /**
     * 获取 App竞价 车辆详情
     */
    carDetailApp=(item: quotationResponse)=>{
        // console.log('item',item.driverUserId)
        
        this.$scope.checkDetailCarid = item.driverUserId;

    }

    /**
     * App竞价 北斗定位
     */
    carDBLocationApp=(item:quotationResponse)=>{
        this.$scope.bd_carCode = item.carCode;
        this.$scope.bd_driverName = item.userRealName;
        this.$scope.bd_phoneNumber = item.phoneNumber;

        this.$scope.bd_creationTime="";
        this.$scope.bd_statusCode="";
        this.$scope.bd_areaInfo=""
        
    }

   


    
    


}

angular.module("tms").controller("orderAcceptBreakController", ["$scope", "$timeout", "locationService", "$state", "$location", "$http", "orderService", "carrierService", "carService", "employeeService",
    "bankService", "valueService", "routeService", "$stateParams", "$ngBootbox", "commonService", "areaService","$rootScope","ossUploaderService", OrderAcceptBreakController]);